package com.vast.admin.controller;

import com.alibaba.fastjson.JSON;
import com.vast.admin.entity.bestsign.BestsignCallbackEntity;
import com.vast.admin.service.BestsignService;
import com.vast.common.core.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 上上签回调接口
 */
@RestController
@RequestMapping("/bestsign")
@Slf4j
public class BestsignController {

    @Autowired
    private BestsignService bestsignService;

    /**
     * 上上签回调接口
     * @param bestsignCallback
     * @return
     */
    @PostMapping("/notify")
    public Result<Void> notify(@RequestBody BestsignCallbackEntity bestsignCallback) {
        if ("signContract".equals(bestsignCallback.getAction())) {
            //合同签署成功回调
            log.info("合同签署成功回调：" + JSON.toJSONString(bestsignCallback));
            bestsignService.signContract(bestsignCallback);
        } else if ("certApply".equals(bestsignCallback.getAction())) {
            //证书申请成功回调
            log.info("证书申请成功回调：" + JSON.toJSONString(bestsignCallback));
            bestsignService.certApply(bestsignCallback);
        } else if ("h5FaceAuth".equals(bestsignCallback.getAction())) {
            //人脸识别认证

        } else if ("signCatalogContract".equals(bestsignCallback.getAction())) {
            //多文档合同签署回调，上上签会针对多文档合同的每个文档签署之后做单独的回调（signContract），
            // 此处多文档合同签署回调不做处理，由单独的回调统一处理
            log.info("多文档合同签署回调：" + JSON.toJSONString(bestsignCallback));
        } else {
            log.warn("上上签其他回调：" + JSON.toJSONString(bestsignCallback));
        }
        return Result.SUCCESS;
    }
}
